package com.webactus.appli;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ArticleAdapter<S> extends ArrayAdapter<Article>{
	int resource;
	
	public ArticleAdapter(Context context, int resource, List<Article> articles) {
		super(context, resource);
		this.resource = resource;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout rssView;
		
		Article article = (Article) getItem(position);
		
		if(convertView == null){
			rssView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater li = (LayoutInflater) getContext().getSystemService(inflater);
			li.inflate(resource, rssView, true);
		}
		else{
			rssView = (LinearLayout)convertView;
		}
		
		TextView titleView = (TextView) rssView.findViewById(R.id.rowtitle);
		TextView urlView = (TextView) rssView.findViewById(R.id.rowurl);
		
		titleView.setText(article.getTitle());
		urlView.setText(article.getUrl().toString());
		
		return rssView;
	}

}
